<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Live\Controller;
use Think\Controller;

class BaseController extends Controller {
	/*
	 * 后台主页显示
	 */
	public function _initialize(){
// 		if(!strpos($_SERVER["HTTP_USER_AGENT"],"Chrome")){
// 			echo "<div style=\"color:#f00; font-size:15px; text-align:center; margin-top:24px;\">为保证后台能更好的展现效果，请使用谷歌Chrome浏览器或360浏览器极速模式</div>";
// 		}
		//setcookie('uvinfo',null);die;
		//setcookie('uvinfo','l!ive@hr&cn');
		if(empty($_COOKIE['uvinfo'])){
			setcookie('uvinfo','l!ive@hr&cn');
		}
		$userinfo = $_COOKIE['user_userinfo'];
		$userinfo_name = $_COOKIE['userinfo_name'];
		if(empty($userinfo)){
			header("Location:".C('LOGINADDRES').getURL());
		}else{
			//http://api.hrtv.cn/newaccount/getuserinfo?token=o4BL8s0_1cX8NaNq8JrR4E2KZAO4
			//获取微信名
			$this->wxname($userinfo,$userinfo_name);
		}
		$this->assign('userinfo',$userinfo);
		$this->assign('userinfo_name',$this->wxuserinfo($userinfo,'nickname'));
		$this->assign('url',getURL());

	}
	//微信名是否存在
	protected function wxname($userinfo,$userinfoname){
		if(empty($userinfoname)){
			$r = request_get(C('APIADDRES1')."/getuserinfo?token=".$userinfo);
			setcookie('userinfo_sex',$r['data']['sex']);		//性别1男 0女
			setcookie('userinfo_name',$r['data']['nickname']);	//昵称
		}
	}

	//获取用户昵称或者性别
	protected function wxuserinfo($userinfo,$field){
		$r = request_get(C('APIADDRES1')."/getuserinfo?token=".$userinfo);
		return $r['data'][$field];
	}

	//上一页来源地址
	function sourceurl(){
		$pageURL = 'http';
		if ($_SERVER["HTTPS"] == "on"){
			$pageURL .= "s";
		}
		$pageURL .= "://";
		if ($_SERVER["SERVER_PORT"] != "80"){
			$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
		}else{
			$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
		}
		return $pageURL;
	}


	/*
	 * 非法访问，超过3次将彻底封锁账号
	 */
	public function blockID($str=null){
		if(empty($str)){
			$str = '非法访问';
		}
		echo $str;
		//判断并封锁账号

	}

	/*
	 * 提示alert
	 */
	public function alertmessage($message,$bakurl){
		echo "<script>alert('".$message."');location.href='".$bakurl."';</script>";
	}

	/*
	 * 显示所有的直播列表信息
	 */
	public function livelist(){
		$result = S('live_list');
		if(!$result){
			$liveing = D(C('TABLE_LIVEING'));
			$where['live_status'] != -1;
			$result = $liveing->order('live_push desc,id desc')->where($where)->select();
			S('live_list',$result);
		}

		$this->assign('list',$result);
	}

	/*
	 * 发送手机验证码
	 */
	public function verifynote($tel=null){
		if(empty($tel)){
			$tel = I('post.usertel');
		}
		$fun= new \Org\Util\fun();
		$tmppwd = substr(mt_rand()."000000",0,6);
		$ssmmess = $fun->SendSms($tel,$tmppwd);
		session('verftel',null);
		session('verftel',$tmppwd);
		//echo $tmppwd;
	}


}